<?php

App::uses('AppController', 'Controller');

class LocationsStatusController extends AppController {
    public $layout     = false;
    public $autoRender = false;

    public $uses = array('Location');

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('index');

        $key = $this->request->header("x-skyboard-api-key");
        if($key != Configure::read('api-key')) {
            $this->response->statusCode(500);
            $this->response->body('Invalid request.');
            $this->response->send();
            die;
        }
    }

    public function index() {
        $list = $this->Location->find('list');
        $ids = array_keys($list);
        sort($ids);

        $status = $this->Location->getStatus($ids);
        foreach($status as $k=>&$v) {
            $v['name'] = $list[$k];
        }

        $this->response->type('json');
        $this->response->body(json_encode($status));
    }
}

?>